/*
 * Copyright 2002-2006 the original author or authors. Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language governing permissions and limitations under the
 * License.
 */
package pikes.html.xhtml;

import pikes.xml.XMLTag;

public aspect CoreAttributesAspect {

    private CoreAttributesImplementation CoreAttributes.coreAttrDelegate = new CoreAttributesImplementation();
    
    public void CoreAttributes.setId(CharSequence id) {
        coreAttrDelegate.setId(id);
    }

    public void CoreAttributes.setClazz(CharSequence clazz) {
        coreAttrDelegate.setClazz(clazz);
    }
    
    public CharSequence CoreAttributes.getId() {
        return coreAttrDelegate.getId();
    }
    
    public CharSequence CoreAttributes.getClazz() {
        return coreAttrDelegate.getClazz();
    }
    
    public void CoreAttributes.setStyle(CharSequence style) {
        coreAttrDelegate.setStyle(style);
    }
    
    public CharSequence CoreAttributes.getStyle() {
        return coreAttrDelegate.getStyle();
    }
    
    public void CoreAttributes.setTitle(CharSequence title) {
        coreAttrDelegate.setTitle(title);
    }
    
    public CharSequence CoreAttributes.getTitle() {
        return coreAttrDelegate.getTitle();
    }
    
    pointcut decorateTag(CoreAttributes coreAttributes) : execution( protected void TagFactory.decorateCreatedTag(..)) && this(coreAttributes) && !within(CoreAttributesImplementation);
    
    after(CoreAttributes coreAttributes) : decorateTag(coreAttributes) {
        XMLTag tag = (XMLTag)thisJoinPoint.getArgs()[0];
        
        coreAttributes.coreAttrDelegate.decorateTag(tag);
        
    }
}

class CoreAttributesImplementation  implements TagDecorator {

    private CharSequence id = null;

    private CharSequence clazz = null;
    
    private CharSequence style = null;
    
    private CharSequence title = null;
    
    public void decorateTag(XMLTag tag) {
        if (id != null) {
            tag.addAttribute("id", id);
        }

        if (clazz != null) {
            tag.addAttribute("class", clazz);
        }
        
        if (style != null) {
            tag.addAttribute("style", style);
        }

        if (title != null) {
            tag.addAttribute("title", title);
        }
    }
    
    public CharSequence getClazz() {
        return clazz;
    }

    public void setClazz(CharSequence clazz) {
        this.clazz = clazz;
    }
    
    public void setId(CharSequence id) {
        this.id = id;
    }
    
    public CharSequence getId() {
        return id;
    }
    
    public void setStyle(CharSequence style) {
        this.style = style;
    }
    
    public CharSequence getStyle() {
        return style;
    }
    
    public void setTitle(CharSequence title) {
        this.title = title;
    }
    
    public CharSequence getTitle() {
        return title;
    }
}